﻿<cfsilent>
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		stringAdvice = getProperty("serviceFactory").getBean("stringAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		
		response = structNew();
		
		structInsert(response, "success", false, true);
		
		teacherId = sessionAdvice.getAutherUserID();
		secureTicket = event.getArg("Sign");
		messageId = event.getArg("MSG");
		messageReply = event.getArg("REPLY");
		
		/* 安全设置 */
		postSecure = false;
		
		/* 首先做安全检查 */
		try {
			stringOrignal = decrypt( secureTicket, teacherId, "PBEWithMD5AndDES", "Hex");
			stringTest = messageId;
			
			if ( stringOrignal eq stringTest ) {
				postSecure = true;
			}
		}
		catch(any excpt) {
		}
		
		if ( postSecure ) {
			
			currentDateTime = datetimeAdvice.getCurrentDatetimeString();
			
			transaction {
				
				sql = "UPDATE t_evaluate_comment 
						SET 
							tch_id = :teacherId, 
							reply = :messageReply, 
							reply_date = :currentDateTime, 
							is_public = '1', 
							is_feed = '1' 
						WHERE 
							msg_id = :messageId ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				
				queryObj.addParam( name="messageId", value=messageId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="currentDateTime", value=currentDateTime, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="messageReply", value=messageReply, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="teacherId", value=teacherId, cfsqltype="cf_sql_varchar" );
				

				queryObj.execute( sql=sql );
				
			}

			structInsert(response, "success", true, true);
			structInsert(response, "messageId", messageId, true);
			structInsert(response, "messageReply", stringAdvice.HTMLEncode( messageReply ), true);
			structInsert(response, "messageDate", datetimeAdvice.formatDatetimeString( currentDateTime, "YYYY-MM-DD" ), true);

		}
		
		
	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>